package com.boot.controller;

import com.boot.pojo.Item;
import com.boot.service.ItemService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/item")
@Tag(name="商品接口",description = "提供商品接口")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @GetMapping("/{id}")
    public Item getItemById(@PathVariable("id") Long id){
        return itemService.getById(id);
    }
    @GetMapping
    public List<Item> getAll(
            @RequestParam(name="currentPage" , defaultValue = "1")Integer currentPage,
            @RequestParam(name="pageSize" , defaultValue = "10")Integer pageSize){
        return this.itemService.getAll(currentPage,pageSize);
    }
    @GetMapping("/list")
    public List<Item> getList(
            @RequestParam(name="currentPage" , defaultValue = "1")Integer currentPage,
            @RequestParam(name="pageSize" , defaultValue = "10")Integer pageSize,
            @RequestParam(name="itemName",defaultValue = "")String itemName,
            @RequestParam(name="itemDetail",defaultValue = "")String itemDetail){
        return this.itemService.getList(currentPage,pageSize,itemName,itemDetail);
    }
}
